<?php

use Biz\service\trade\Cart as sCart;
use Doraemon\tools\ActionLog as tActionLog;

/**
 * @deprecated
 */
class DelSkuAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_VISITOR;

    const ACTION_TYPE = tActionLog::BIZ_CART_LIST;

    const DEFAULT_LOGIN_COPY_WRITING = "登录后\n收藏心愿好物";

    public function main()
    {
        $skuIds = $this->getRequest()->getPost('sku_ids');
        $toFav = $this->getRequest()->getPost('to_fav');

        if ($toFav == 1 && empty($this->uid)) {
            throw new \Exception("登录后\n收藏心愿好物", self::API_CODE_NEED_LOGIN);
        }

        $skuIds = explode(',', $skuIds);

        if ($skuIds) {
            $skuIds = array_filter($skuIds, function ($v) {
                return !empty($v);
            });
        }

        sCart::delSku(($this->uid > 0) ? $this->uid : $this->vid, $skuIds, $toFav, $this->appType);

        $this->setSuccess();
    }
}